package cn.edu.ssm.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.ssm.entity.Media;
import cn.edu.ssm.entity.Type;
import cn.edu.ssm.service.HomeService;

@Controller
public class HomeController {
	@Autowired
	private HomeService homeService;

	@Value("${mediatype.photo}")
	private String PHOTO_TYPE;
	@Value("${mediatype.vedio}")
	private String VEDIO_TYPE;

	// 显示首页
	@RequestMapping("/index.action")
	public String getNewMedia(Model model) throws Exception {
		List<Media> plist = homeService.getNewMedias(PHOTO_TYPE);
		model.addAttribute("plist", plist);
		List<Media> vlist = homeService.getNewMedias(VEDIO_TYPE);
		model.addAttribute("vlist", vlist);
		model.addAttribute("active",1);
		return "index";
	}
	// 浏览图片
	@RequestMapping("/photoview.action")
	public String photoview(Model model, String mediaid, String medianum) throws Exception {
		List<Media> plist = homeService.getPhotoView(PHOTO_TYPE, medianum);
		model.addAttribute("plist", plist);
		model.addAttribute("mediaid", mediaid);
		return "photo_view";
	}
	// 显示图片列表
	@RequestMapping("/photolist.action")
	public String photoList(Model model) throws Exception {
		List<Media> plist = homeService.getMediaList(PHOTO_TYPE);
		model.addAttribute("plist", plist);
		model.addAttribute("active",2);
		return "photo_list";
	}
	// 显示视频列表
	@RequestMapping("/videolist.action")
	public String videoList(Model model) throws Exception {
		List<Media> vlist = homeService.getMediaList(VEDIO_TYPE);
		model.addAttribute("vlist", vlist);
		model.addAttribute("active",3);
		return "video_list";
	}
	// 显示分类查看页面
	@RequestMapping("/typelist.action")
	public String typelist(Model model) throws Exception {
		List<Type> list = homeService.getTypeList();
		model.addAttribute("list", list);
		model.addAttribute("active",4);
		return "type_list";
	}
	// 显示数据统计
	@RequestMapping("/statistic.action")
	public String statistic(Model model) throws Exception {
		List<Map<String,Object>> list = homeService.getStatistic();
		model.addAttribute("list", list);
		model.addAttribute("active",5);
		return "statistic_list";
	}


}
